﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TYGRPDCBB
    {
        ITXEXRPT ITXEXRPT;
        public TYGRPDCBB()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_PDC();
            this.DataContext = MV;
            InitializeComponent();
            if (app.User.Trim() == "ITXV")
            {
                DTSTART = "20150820";
                DTEND = "20150901";
            }
        }
        public override void DTEND_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            base.DTEND_SelectedDateChanged(sender, e);
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                dwData = TBMain.NewRow();
                string BDE = txtBDE.Text.ToString().Trim();
                string STAFF = txtSTAFF.Text.ToString().Trim();
                string LOT = txtLOT.Text.ToString().Trim();

                if (BDE == "")
                {
                    BDE = "AAA";
                }
                if (LOT == "")
                {
                    LOT = "AAA";
                }
                if (DTSTART == "")
                {
                    DTSTART = "20000000";
                }
                if (DTEND == "")
                {
                    DTEND = "99999999";
                }
                dwData["PDCDATE"] = " AND PDCDATE >=" + DTSTART + " AND PDCDATE <=" + DTEND;
                dwData["ABFAGANG"] = "XS";
                dwData["JP10"] = " AND (TRIM(JP10) =  '" + LOT + "' or  '" + LOT + "' = 'AAA') ";
                dwData["PDCSTAFF"] = " AND TRIM(PDCSTAFF) LIKE '" + STAFF + "%' "; 
                dwData["AMBDEMA"] = " AND (TRIM(AMBDEMA) =  '" + BDE + "' OR  '" + BDE + "' = 'AAA') ";
                SResult = TMV.QPDC05(dwData);
                MergeData(SResult, false);  
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();//这里是实例化
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }

                ITXEXRPT.dsSource = new System.Data.DataSet();
                ITXEXRPT.dsSource.Merge(TMV.SetProd);
                ITXEXRPT.DocType = app.company + "PDC";
                ITXEXRPT.strExcelFile = app.company + @"\YGRREPORT.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }

        private void btnQExport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                dwData = TBMain.NewRow();
                string BDE = txtBDE.Text.ToString().Trim();
                string STAFF = txtSTAFF.Text.ToString().Trim();
                string LOT = txtLOT.Text.ToString().Trim();

                if (BDE == "")
                {
                    BDE = "AAA";
                }
                if (LOT == "")
                {
                    LOT = "AAA";
                }
                if (DTSTART == "")
                {
                    DTSTART = "20000000";
                }
                if (DTEND == "")
                {
                    DTEND = "99999999";
                }
                dwData["PDCDATE"] = " AND PDCDATE >=" + DTSTART + " AND PDCDATE <=" + DTEND;
                dwData["ABFAGANG"] = "XS";
                dwData["JP10"] = " AND (TRIM(JP10) =  '" + LOT + "' or  '" + LOT + "' = 'AAA') ";
                dwData["PDCSTAFF"] = " AND TRIM(PDCSTAFF) LIKE '" + STAFF + "%' ";
                dwData["AMBDEMA"] = " AND (TRIM(AMBDEMA) =  '" + BDE + "' OR  '" + BDE + "' = 'AAA') ";
                SResult = TMV.QPDC05(dwData);
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();//这里是实例化
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }

                ITXEXRPT.dsSource = new System.Data.DataSet();
                ITXEXRPT.dsSource.Merge(SResult);
                ITXEXRPT.DocType = app.company + "PDC";
                ITXEXRPT.strExcelFile = app.company + @"\YGRREPORT.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }
    }
}
